<!--
 * @FilePath: 02累乘器.html
 * @Author: 苏苏少年
 * @Date: 2022-11-25 19:44:48
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var n = 1;
        // // 累乘器
        // // 计算5的阶乘 
        // var n = 1;
        // var s = Number(prompt("请输入你的数字n:"));
        // for(var i = 1; i <= s; i++){
        //     n *= i;
        // }
        // alert(s + "的阶乘为:" + n);


        var n = Number(prompt("请输入n的值:"))
        var sum = 0;
        var s = 1;
        // 假设n是5
        for(var i = 1; i<=n; i++){
            s *= i / (i*2+1)  // s = s(1) *  1/3    ;  s1 = 1/3 * 2/5 
            sum += s   // sum = sum + s (1/3)   ; 1/3 + s1
        }
        var total = 2 * (sum + 1);
        alert(total);

    </script>
    
</body>
</html>